<template>
    <div class="login-wrap">
        <div class="ms-login">
            <div style="font-size: 1.2rem;color: #fff;text-align: center;">飞天佳园后台管理</div>
            <div class="ms-title">
                <!--<img src="https://dlhz.oss-cn-beijing.aliyuncs.com/xey-upload/CyiDychteJ.jpg?x-oss-process=image/resize,w_60,h_60" alt="" style="border-radius: 5px;vertical-align: bottom;">-->
                <div>登录</div>
            </div>
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="0px" class="ms-content">
                <el-form-item prop="username">
                    <!--<el-input v-model="ruleForm.username" placeholder="username">-->
                    <!--<el-button slot="prepend" icon="el-icon-lx-people"></el-button>-->
                    <!--</el-input>-->
                    <input type="text" class="inp inpname" placeholder="账号" v-model="ruleForm.username">
                </el-form-item>
                <el-form-item prop="password">
                    <!--<el-input type="password" placeholder="password" v-model="ruleForm.password" @keyup.enter.native="submitForm('ruleForm')">-->
                    <!--<el-button slot="prepend" icon="el-icon-lx-lock"></el-button>-->
                    <!--</el-input>-->
                    <input type="password" class="inp inpname" placeholder="密码" v-model="ruleForm.password" @keyup.enter.enter="submitForm('ruleForm')">
                </el-form-item>
                <div class="forgotPwd">忘记密码？</div>
                <div class="login-btn">
                    <el-button class="loginBtn" type="primary" @click="submitForm('ruleForm')">登录</el-button>
                </div>
                <!--<div class="login-btn">-->
                <!--<el-button @click="goRegister">注册</el-button>-->
                <!--</div>-->
                <!--<p class="login-tips">Tips : 用户名和密码随便填。</p>-->
            </el-form>
        </div>
    </div>
</template>

<script>
    import md5 from 'md5'
    import upload from '../common/Upload'
    export default {
        components:{upload},
        data(){
            var v1 = (rule, value, callback) => {
                if (!value) {
                    callback(new Error('输入账号'));
                } else {
                    callback();
                }
            };
            var v2 = (rule, value, callback) => {
                if (value.length<6||value.length>16) {
                    callback(new Error('6-16位密码'));
                } else {
                    callback();
                }
            };
            return {
                ruleForm: {
                    username: '18100000000',
                    password: '123456'
                },
                rules: {
                    username: [
                        { required: true, validator: v1, message: '请输入账号', trigger: 'blur' }
                    ],
                    password: [
                        { required: true, validator: v2, message: '请输入6-16位密码', trigger: 'blur' }
                    ]
                }
            }
        },
        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        // localStorage.setItem('ms_username',this.ruleForm.username);
                        // this.$router.push('/');
                        this.getLogin();
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            // 登录方法
            getLogin(){
                this.config.post('/housinggestate/login/login', {
                    mobile: this.ruleForm.username,
                    password: md5(this.ruleForm.password),
                }).then(res=>{
                    if(res.data.code==='0'){
                        this.$message.success(res.data.message)
                        sessionStorage.setItem('token', res.data.token);
                        this.config.headers.token = res.data.token;
                        this.$router.push('/');
                    }else{
                        this.$message.error(this.config.handleError(res.data));
                    }
                }).catch();
            },
            goRegister(){
                this.$router.push('/register');
            },
            backfile(filename){
            },
        }
    }
</script>

<style scoped>
    .login-wrap{
        position: relative;
        width:100%;
        height:100%;
        background-image: url(http://jzkj02.oss-cn-hangzhou.aliyuncs.com/file/xwr1578045052726.png);
        background-size: 100%;

        display: flex;
        justify-content: center;
    }
    .ms-title{
        width:100%;
        line-height: 50px;
        text-align: left;
        font-size:20px;
        color: #fff;
        margin-bottom: 20px;
        /*border-bottom: 1px solid #ddd;*/
    }
    .ms-login{
        position: absolute;
        left:50%;
        top:50%;
        width:350px;
        height: 500px;
        margin:-190px 0 0 -150px;
        border-radius: 5px;
        /*background: rgba(255,255,255, 0.3);*/
        overflow: hidden;
    }
    .ms-content{
        /*padding: 30px 30px;*/
    }
    .login-btn{
        text-align: center;
    }
    .login-btn .loginBtn{
        font-size: 1rem;
    }
    .login-btn button{
        width:100%;
        height:45px;
        margin-bottom: 10px;
        border-radius: 30px;
        /*background-color: rgba(0,0,0,1);*/
        background-color: #124b3b;
        box-shadow: 0 0 1px 0 #ccc;
        border: none;
        /*background-image: url("http://jzkj02.oss-cn-hangzhou.aliyuncs.com/file/7Pb1578045929550.png");*/
        background-size: 100% 100%;
    }
    .login-tips{
        font-size:12px;
        line-height:30px;
        color:#fff;
    }
    .el-form-item:first-of-type{
        margin-bottom: 50px;
    }
    .ms-login .inp{
        width: 100%;
        background: none;
        outline: none;
        border: none;
        border-bottom: 2px solid #3C4E67;
        font-size: 1rem;
        color: #fff;
        padding: 0.5rem 0.2rem;
    }
    /*忘记密码*/
    .forgotPwd{
        text-align: right;
        font-size: 0.8rem;
        color: #fff;
        margin-bottom: 3rem;
        cursor: pointer;
    }
    /*左侧LOGO*/
    .logoBox{
        position: absolute;
        left:47%;
        top:50%;
        width:350px;
        padding: 20px 20px 100px;
        margin:-190px 0 0 -400px;
        overflow: hidden;
        border-right: 1px solid #3c4e67;
    }
</style>
